package com.etc.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.etc.dao.DeptDao_HashMap;
import com.etc.entity.Dept;

import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class DeptManage_UI_AddDept extends JFrame {

	private JPanel contentPane;
	private JTextField txtDeptName;
	private JTextField txtDeptAddress;
	
	private DeptDao_HashMap dd = new DeptDao_HashMap();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DeptManage_UI_AddDept frame = new DeptManage_UI_AddDept();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public DeptManage_UI_AddDept() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 410, 313);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtDeptName = new JTextField();
		txtDeptName.setBounds(148, 58, 179, 27);
		contentPane.add(txtDeptName);
		txtDeptName.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("部门名称");
		lblNewLabel.setBounds(58, 53, 73, 36);
		contentPane.add(lblNewLabel);
		
		txtDeptAddress = new JTextField();
		txtDeptAddress.setColumns(10);
		txtDeptAddress.setBounds(148, 124, 179, 27);
		contentPane.add(txtDeptAddress);
		
		JLabel label = new JLabel("部门地址");
		label.setBounds(58, 119, 73, 36);
		contentPane.add(label);
		
		JButton btnAdd = new JButton("增加部门");
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				//增加部门
				String deptName = txtDeptName.getText();
				String deptAddress = txtDeptAddress.getText();
				Dept dept = new Dept(deptName, deptAddress);
				// 调用Dao添加的方法
				boolean flag = dd.addDept(dept);
				if (flag) {
					JOptionPane.showMessageDialog(null,"部门 [" + deptName + "] 增加成功");
				} else {
					JOptionPane.showMessageDialog(null,"部门 [" + deptName + "] 增加失败");
				}
				
			}
		});
		btnAdd.setBounds(65, 213, 93, 23);
		contentPane.add(btnAdd);
		
		JButton button_1 = new JButton("关闭");
		button_1.setBounds(219, 213, 93, 23);
		contentPane.add(button_1);
	}

}
